<%@ page language="java" pageEncoding="UTF-8" %>
<%@ include file="/common/taglibs.jsp" %>

<%--
 jQuery-File-Upload(最小化安装)
--%>
<link href="${ctx}/static/js/jquery-fileupload/9.9.3/css/jquery.fileupload.css" rel="stylesheet">
<script src="${ctx}/static/js/jquery-fileupload/9.9.3/js/vendor/jquery.ui.widget.js"></script>
<script src="${ctx}/static/js/jquery-fileupload/9.9.3/js/jquery.iframe-transport.js"></script>
<script src="${ctx}/static/js/jquery-fileupload/9.9.3/js/jquery.fileupload.js"></script>
<script src="${ctx}/static/js/jquery-fileupload/9.9.3/js/jquery.fileupload-process.js"></script>
<%--<script src="${ctx}/static/js/jquery-fileupload/9.9.3/js/jquery.fileupload-image.js"></script>--%>
<%--<script src="${ctx}/static/js/jquery-fileupload/9.9.3/js/jquery.fileupload-audio.js"></script>--%>
<%--<script src="${ctx}/static/js/jquery-fileupload/9.9.3/js/jquery.fileupload-video.js"></script>--%>
<script src="${ctx}/static/js/jquery-fileupload/9.9.3/js/jquery.fileupload-validate.js"></script>
<%--<script src="${ctx}/static/js/jquery-fileupload/9.9.3/js/jquery.fileupload-ui.js"></script>--%>

<script>
    $(function () {

        $.extend($.blueimp.fileupload.prototype.options.messages, {
            maxNumberOfFiles: '上传文件个数超过最大限制 ',
            acceptFileTypes: '上传文件格式不支持 ',
            maxFileSize: '上传文件太大 ',
            minFileSize: '上传文件太小 '
        });

        //添加默认设置。
        $.fn.fileupload2 = function (option) {
            return this.each(function () {
                var options = $.extend({
                    url: MH.ctx + '/api/attachment/upload;jsessionId=${pageContext.session.id}',
                    dataType: 'json',
                    maxFileSize: 100000000, // 100 MB,
                    singleFileUploads: true,//一次只上传一个文件
                    acceptFileTypes: /(\.|\/)(gif|jpg|png|bmp|jpeg|doc|docx|wps|dot|wpt|xlsx|xls|ppt|pot|pps|dpt|dps|rar|7z|zip|pdf)$/i,
                    fileuploadprocessalways: function (e, data) {
                        var index = data.index,
                                file = data.files[index];
                        if (file.error) {
                            MH.notify({content: file.error, type: 'error'});
                        }
                    },
                    progressall: function (e, data) {
                        var progress = parseInt(data.loaded / data.total * 100, 10);
                        $('#progress .progress-bar').css(
                                'width',
                                progress + '%'
                        );
                    }
                }, option);
                return $(this).fileupload(options);
            })
        }
    })
</script>